<?php
/**
 * Created by PhpStorm.
 * User: tony
 * Date: 2018/6/4
 * Time: 11:20
 */

namespace app\modules\v1\controllers;

use app\models\Region;
use app\modules\v1\controllers\parent\ParentController;

class RegionController extends ParentController
{
    public function actionIndex(){
        $params = \Yii::$app->request->getQueryParams();
        $query = Region::find();
        $query->andWhere(['status'=>1]);
        if(isset($params['level']))
            $query->andWhere(['level'=>$params['level']]);
        if(isset($params['parent_id']))
            $query->andWhere(['parent_id'=>$params['parent_id']]);
        $query->orderBy('sort ASC');
        return $query->all();
    }

    public function actionFullAddress(){
        $params = \Yii::$app->request->getQueryParams();
        return ['fullAddress'=>Region::getNameById((int)$params['regionId'])];
    }
}